package com.bjfu.demo.dto;

import com.bjfu.demo.entity.Article;
import com.bjfu.demo.valid.AddGroup;
import com.bjfu.demo.valid.UpdateGroup;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.lang.Nullable;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Data
@NoArgsConstructor
public class ArticleDto {
    @Nullable
    @NotNull(message = "文章id不能为空", groups = UpdateGroup.class)
    private Integer id;
    @NotBlank(message = "文章标题不能为空", groups = AddGroup.class)
    private String title;
    @NotBlank(message = "文章内容不能为空", groups = AddGroup.class)
    private String content;

    public void copyFromArticleToArticleDto(Article article) {
        this.id = article.getId();
        this.title = article.getTitle();
        this.content = article.getContent();
    }
}
